package com.itic.hpp.project.express;

import com.itic.appbase.framework.Base.BaseCode;
import com.itic.appbase.framework.utils.ValueHelper;
import com.itic.mobile.base.BaseMobile;
import com.itic.system.project.express.persistence.model.ProjectExpress;
import com.itic.system.project.express.service.ProjectExpressService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/hpp/project/express")
public class ProjectExpressInterface extends BaseMobile {

    @Autowired
    private ProjectExpressService projectExpressService;
    private static String[] ignoreProperties = new String[] { "createUser", "isEffective", "updateTime", "orgCode","orderNo","isDefaut","expressPhone","gjpCode" };

    /**
     * 快递信息列表
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/expressList")
    @ResponseBody
    public Map<String,Object> expressList(HttpServletRequest request, HttpServletResponse response){
        Map<String, Object> resultMap = new HashMap<String,Object>();
        try{
            List<ProjectExpress> projectExpresses = this.projectExpressService.findAllProjectExpress();
            List<Map<String, Object>> resultList = new ArrayList<>();
            resultList = ValueHelper.tranList2MapList(projectExpresses, ignoreProperties);
            resultMap.put(BaseCode.DATA, resultList);
            resultMap.put(BaseCode.CODE, BaseCode.SUCCESS_ERROR_CODE);
            resultMap.put(BaseCode.MSG, BaseCode.SUCCESS_ERROR_MSG);
        }catch(Exception e){
            resultMap.put(BaseCode.CODE, BaseCode.SERVER_ERROR_CODE);
            resultMap.put(BaseCode.MSG, BaseCode.SERVER_ERROR_MSG);
            logException("ProjectExpressInterface", "expressList", e.toString(),"物流公司列表",e);
        }
        return resultMap;
    }
}
